function a=EKF_weight_v3(S1,Fnk,Outputs,a_pre,v_o,w_o,aph,b)

    coder.inline("never");

 % 初始化静态变量
    persistent P0;
    if isempty(P0)
            P0=0.01*eye(32);
    end
    %生成雅可比矩阵
    numOutputs=2;
    numRules=16;
    dv=zeros(1,32);
    dw=zeros(1,32);
    Index=1;
    for i=1:numOutputs
        for j=1:numRules
            dvi=(Fnk(j)*sum(S1(:)))/(2*power(1+aph*Outputs(i),2));
            if(i==1)
                dwi=(Fnk(j)*sum(S1(:)))/(2*b*power(1+aph*Outputs(i),2));
            else
                dwi=-(Fnk(j)*sum(S1(:)))/(2*b*power(1+aph*Outputs(i),2));
            end
            dv(Index)=dvi;
            dw(Index)=dwi;
            Index=Index+1;
        end
    end
    O_k=[dv;dw];
    % 观测噪声协方差矩阵 R
    R = 0.01;
    % 过程噪声协方差矩阵 Q
    Q = 0.01 * eye(size(a_pre,2));
    % 卡尔曼增益 K
    K = P0*O_k'/(R+O_k*P0*O_k');
    o=[v_o;w_o];
    od=O_k*a_pre';
    e=o-od;
    %step end
    %
    %更新权重和P
    a_update=a_pre+(K*e)';
    P=(eye(32)-K*O_k)*P0+Q;
    %
    a=a_update;
    P0=P;
    %step end
end